/***************************************************************************
 *   Copyright (C) 2014 by Docteur Pierre-Marie Desombre.   *
 *   pm.desombre@medsyn.fr  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 3 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "mdp.h"
#include <QDir>
#include <QFile>
#include <QSettings>

Mdp::Mdp(QObject *parent)
{
  Q_UNUSED(parent);
  setupUi(this);
  loginEdit -> setText("root");
  hostEdit -> setText("localhost");
  QString dotrequetespath = QDir::homePath()+QDir::separator()+".requetes";
  QDir dotrequetesdir(dotrequetespath);
  if (!dotrequetesdir.exists())
  {
      dotrequetesdir.mkpath(dotrequetespath);
      dotrequetesdir.mkdir(dotrequetespath);
      }
  
  m_mdpini = dotrequetespath+QDir::separator()+"mdp.ini";
  QFile filemdp(m_mdpini);
  if (!filemdp.exists())
  {
      QString resourcemdpconfigstr = qApp->applicationDirPath()+QDir::separator()+".."+QDir::separator()+"resources"+QDir::separator()+"config"+QDir::separator()+"mdpini.ini";
      QFile fileconfigmdp(resourcemdpconfigstr);
      fileconfigmdp.copy(m_mdpini);
      }
  QSettings set(m_mdpini,QSettings::IniFormat);
  m_mdpstck = set.value("passwd/pass").toString();
  if (m_mdpstck.isEmpty())
  {
      passEdit->setFocus();
      passEdit->setText("Inscrivez votre mot de passe Mysql");
      }
  else  passEdit->setText(m_mdpstck);
}

Mdp::~Mdp(){}

QString Mdp::mdpLogin(){
  return loginEdit->text();
}
QString Mdp::mdpPassword(){
  QString pathedittext = passEdit->text();
  QSettings set(m_mdpini,QSettings::IniFormat);
  set.setValue("passwd/pass",pathedittext);
  return pathedittext;
}

QString Mdp::mdpHost(){
  return hostEdit->text();
}

QString Mdp::mdpPort(){
  return portEdit->text();
}




